﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinApp.i18n;
using WinApp.Properties;

namespace WinApp.Until
{
    public static class SwitchMode
    {
        public const string OnLine = "OnLine";
        public static string OffLine = "OffLine";
    }
    public class UtilHelper
    {
        private static string switchModeFile = "switchMode.txt";

        /// <summary>
        /// 分钟转换为00:00:00格式
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static string DoubleTimeToString(double? time)
        {
            string defautNullTime = "00:00:00"; // 时间为0是默认为此格式
            if (time > 0)
            {
                var newtime = (long)time;
                var hour = newtime / 3600;
                var min = (newtime % 3600) / 60;
                var second = (newtime % 3600) % 60;
                return string.Format("{0:D2}:{1:D2}:{2:D2}", hour.ToString("D2"), min.ToString("D2"), second.ToString("D2"));
            }
            else
            {
                return defautNullTime;
            }

        }

        public static string GetLearningStatusStr(int LearningStatu)
        {
            string statusStr = string.Empty;

            switch (LearningStatu)
            {
                case 1:
                    statusStr = Language.GetLang("incomplete");
                    //lbStatus.ForeColor = Color.Orange;
                    break;
                case 2:
                    statusStr = Language.GetLang("completed");
                    //lbStatus.ForeColor = Color.Green;
                    break;
                default:
                    statusStr = Language.GetLang("notStarted");
                    break;
            }

            return statusStr;
        }

        public static string GetExamStatusStr(int Status)
        {
            string statusStr = string.Empty;
            switch (Status)
            {
                case 0:
                case 1:
                case 2:
                    statusStr = Language.GetLang("notStarted");
                    break;

                case 3:
                    statusStr = Language.GetLang("page__Passed");
                    break;

                case 4:
                    statusStr = Language.GetLang("page_Failed");
                    break;

                case 5:
                    statusStr = Language.GetLang("page_waitExam");
                    break;
                case 6:
                    statusStr = Language.GetLang("page_Incompleted");
                    break;
                case 7:
                    statusStr = Language.GetLang("page_waitRead");
                    break;
                default:
                    statusStr = Language.GetLang("notStarted");
                    break;
            }

            return statusStr;
        }

        public static string ReadSwitchMode()
        {
            if (System.IO.File.Exists(switchModeFile))
            {
                return System.IO.File.ReadAllText(switchModeFile);
            }
            return SwitchMode.OnLine;
        }

        public static void SetSwitchMode(string SwitchMode)
        {
            System.IO.File.WriteAllText(switchModeFile, SwitchMode);
            GlobalVariables.SystemSwitchModel = SwitchMode;
        }
        public static string InitSwitchMode()
        {
            var result = string.Empty;
            if (System.IO.File.Exists(switchModeFile))
            {
                result = System.IO.File.ReadAllText(switchModeFile);//读取文件;
            }
            else
            {//默认在线
                System.IO.File.WriteAllText(switchModeFile, SwitchMode.OnLine);//写入文件                
            }
            return result;
        }


        public static void CloseSystem()
        {
            try
            {
                Application.Exit();
            }
            catch (Exception)
            {
                System.Environment.Exit(0);
            }
        }

        public static void ResetSystem()
        {
            try
            {
                Application.Restart();
            }
            catch (Exception)
            {
                System.Environment.Exit(0);
            }
        }

        /// <summary>
        /// 询问框
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="showMask"></param>
        /// <param name="defaultButton"></param>
        /// <returns></returns>
        public static bool ShowAskDialog(string msg, bool showMask = false, UIMessageDialogButtons defaultButton = UIMessageDialogButtons.Ok)
        {
            return UIMessageDialog.ShowMessageDialog(msg, UILocalize.AskTitle, showCancelButton: true, UIStyle.Blue, showMask, topMost: true, defaultButton);
        }

        public static void ShowSuccessTip(string text, int delay = 1000, bool floating = true)
        {
            UIMessageTip.ShowOk(text, delay, floating);
        }

        public static void ShowErrorTip(string text, int delay = 1000, bool floating = true)
        {
            UIMessageTip.ShowError(text, delay, floating);
        }

    }
}
